package client.comm.baoding.ui

import android.content.Intent
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.R
import client.comm.baoding.adapter.page.KtOrderPageAdapter
import client.comm.baoding.databinding.ActivityKtjlBinding
import client.comm.baoding.ui.vm.TxjlViewModel
import client.comm.commlib.toast.toast

/**
 * 可提记录
 */
class KtOrderActivity : BaseMiddleActivity<TxjlViewModel, ActivityKtjlBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_ktjl
    }

    val adapter: KtOrderPageAdapter by lazy {
        KtOrderPageAdapter(supportFragmentManager)
    }

    override fun initViewModel(): TxjlViewModel = createViewModel()

    override fun initView() {
        binding.event = this
        binding.viewPager.adapter = adapter
        binding.tabLayout.setupWithViewPager(binding.viewPager)

    }

    override fun observerUI() {
        viewModel.cancleCall.observe(this, {
            it?.let {
                if (it.isSuccess) {
                    toast("取消成功")
                    viewModel.pageOne.value = 0
                    viewModel.holdOneKTx()
                    viewModel.pageTwo.value = 0
                    viewModel.holdTwoKTx()
                }
            }
        })
        viewModel.withdraw_order_pay.observe(this, {
            it?.let {
                if (it.isSuccess) {
                    it.data?.let {
                        startActivity(Intent(this, Bank3CodeActivity::class.java).apply {
                            putExtra("bank_bind", it)
                            putExtra("status", "3")
                        })
                    }
                }
            }
        })
    }

}